package com.qianfeng.smartdevice.controller;


import com.github.pagehelper.PageInfo;
import com.qianfeng.smartdevice.dto.R;
import com.qianfeng.smartdevice.pojo.Categories;
import com.qianfeng.smartdevice.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/categories")
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;


    @GetMapping("/categories")
    public R getAllCategories(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, String categoryname, @RequestParam(defaultValue = "-100") Long status) {
        PageInfo<Categories> pageInfo = categoryService.findAllCategoriesByPage(page, limit,categoryname,status);
        return R.setOk(pageInfo);
    }

    @PostMapping("/category")
    public R addCategory(@RequestBody Categories categories) {
        categoryService.addCategory(categories);
        return R.setOk(null);
    }
}
